package com.mvpandroiddemo.register;

import android.text.TextUtils;

import com.mvpandroiddemo.base.BasePresenter;

/**
 * @Description $description$
 * @Author owner
 * @CreateTime 2019/10/15 14:31
 **/
public class RegisterPresent extends BasePresenter<RegisterActivity> implements RegisterControl.IRegisterPresenter {

    private RegisterModel registerModel;

    public RegisterPresent() {
        registerModel = new RegisterModel(this);
    }

    @Override
    public void onRegister() {
        RegisterActivity registerActivity = baseView.get();
        String userName = registerActivity.getUserName();
        String pwd = registerActivity.getPwd();
        String rePwd = registerActivity.getRePwd();

        if (TextUtils.isEmpty(userName)) {
            registerActivity.registerFailed("请输入账号");
            return;
        }

        if (TextUtils.isEmpty(pwd)) {
            registerActivity.registerFailed("请输入密码");
            return;
        }

        if (TextUtils.isEmpty(rePwd)) {
            registerActivity.registerFailed("请确认密码");
            return;
        }

        if (!TextUtils.equals(pwd, rePwd)) {
            registerActivity.registerFailed("密码不一致!请重新确认密码");
            return;
        }

        registerActivity.showDialog();
        registerModel.onRegister(userName, pwd, rePwd,
                new RegisterControl.IRegisterModel.OnRegisterListener() {
                    @Override
                    public void onRegisterSuccess(RegisterBean registerBean) {
                        registerActivity.registerSuccess();
                    }

                    @Override
                    public void onRegisterFailed(String msg) {
                        registerActivity.registerFailed(msg);
                    }
                });
    }


}
